package com.mb.app.service;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mb.app.dao.TbTagCfgMapper;
import com.mb.app.domain.TbTagCfg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 标签配置  服务实现类
 * </p>
 *
 * @author liliping
 * @since 2019-04-01
 */
@Service
@Slf4j
public class TbTagCfgServiceImpl extends ServiceImpl<TbTagCfgMapper, TbTagCfg> implements ITbTagCfgService {

    @Override
    public List<TbTagCfg> queryList(Map<String, Object> map) {
        List<TbTagCfg> list = this.baseMapper.lst(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.countt(map);
    }

    @Override
    public int save(TbTagCfg TbTagCfg) {
        TbTagCfg.setCreateTime(new Date());
        return this.baseMapper.insert(TbTagCfg);
    }

    @Override
    public int update(TbTagCfg TbTagCfg) {
        try {
            TbTagCfg TbTagCfg1 = new TbTagCfg();
            TbTagCfg1.setTagId(TbTagCfg.getTagId());
            TbTagCfg1.setDataStatus(1);
            TbTagCfg TbTagCfgDO = this.baseMapper.selectOne(TbTagCfg1);
            if(TbTagCfgDO != null){
                TbTagCfg.setUpdateTime(new Date());
                this.baseMapper.updateById(TbTagCfg);
            }
        } catch (Exception e) {
            log.error("update Exception",e);
        }
        return 0;
    }


    @Override
    public int remove(Long shipId,Long delUserId) {
//        return this.baseMapper.deleteById(appId);
        TbTagCfg TbTagCfg = new TbTagCfg();
        TbTagCfg.setTagId(shipId);
        TbTagCfg.setDeleteTime(new Date());
        TbTagCfg.setDataStatus(0);
        TbTagCfg.setDeleteUserId(delUserId);
        return this.baseMapper.updateById(TbTagCfg);
    }

    @Override
    public TbTagCfg getDtl(Long tagId) {
        TbTagCfg TbTagCfg = this.baseMapper.selectById(tagId);
        return TbTagCfg;
    }

    @Override
    public boolean tagCfgNameExit(Map<String, Object> params) {
        boolean exit;
        exit = this.baseMapper.selectByTagCfgInfo(params).size() > 0;
        return exit;
    }
	
}
